package com.example.cs499final;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class DBHelper extends SQLiteOpenHelper {
	//variables
	final private Context context;
	private static final int DB_VERSION = 1;
	//table schema
	public static final String NAME = "app_db";
	public static final String COL_ID = "_id";
	public static final String COL_USER = "cUser";
	public static final String COL_PASS = "cPass";
	public static final String COL_NAME = "cName";
	public static final String COL_LAST = "cLastName";
	//create table query
	private final static String CREATE = 
			"CREATE TABLE "+NAME+" ("+COL_ID+" INTEGER PRIMARY KEY AUTOINCREMENT, "
			+COL_USER+" TEXT NOT NULL, "
			+COL_PASS+" TEXT NOT NULL, "
			+COL_NAME+" TEXT NOT NULL, "
			+COL_LAST+" TEXT NOT NULL);";
	//CONSTRUCTOR
	public DBHelper(Context context) {
		super(context, NAME, null, DB_VERSION);
		this.context = context;
	}
	
	@Override
	public void onCreate(SQLiteDatabase db) {
		db.execSQL(CREATE);
	}
	
	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		db.execSQL("DROP TABLE IF EXISTS "+ NAME);
		onCreate(db);
	}
	
	public void eraseData() {
		context.deleteDatabase(NAME);
	}
}